﻿using System;
using System.Xml;
using System.Xml.Linq;

namespace YJKRevitBase.XmlUtility
{
	public sealed class XmlUtilityMethod
	{
		public static XmlElement LinqToXmlElement(XElement xElement)
		{
			if (xElement == null)
			{
				return null;
			}
			XmlElement result = null;
			XmlReader xmlReader = null;
			try
			{
				XmlDocument xmlDocument = new XmlDocument();
				xmlReader = xElement.CreateReader();
				result = (xmlDocument.ReadNode(xmlReader) as XmlElement);
			}
			catch
			{
			}
			finally
			{
				if (xmlReader != null)
				{
					xmlReader.Close();
				}
			}
			return result;
		}

		public static XElement XMLToinq(XmlElement xmlElement)
		{
			if (xmlElement == null)
			{
				return null;
			}
			XElement result = null;
			try
			{
				XmlDocument xmlDocument = new XmlDocument();
				xmlDocument.AppendChild(xmlDocument.ImportNode(xmlElement, true));
				result = XElement.Parse(xmlDocument.InnerXml);
			}
			catch
			{
			}
			return result;
		}
	}
}
